package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.User;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Set;

/**
 * 销售单
 *
 * @author: 袁首京<yuanshoujing@gmail.com>
 * 16/4/13
 */
@Entity
@Table(name = "bill_sale")
public class SaleBill extends Bill {

//    @JSONField(serialize = false)
    @OneToMany(mappedBy = "owner")
    protected Set<SaleBillEntry> entries; // 分录

    @JSONField(serialize = false)
    @ManyToOne
    private User member; // 会员

    @Column(nullable = false)
    private BigDecimal receivable = BigDecimal.ZERO; // 应收

    @Column(nullable = false)
    private BigDecimal received = BigDecimal.ZERO; // 实收

    @Transient
    private String memberId;
    @Transient
    private String memberName;
    @Transient
    private String oldSaleBillId;//挂单单头ID
    
    @Transient
    private Integer payment=0;

    @Column(name = "member_balance")
    private BigDecimal memberBalance; //会员余额

    public Integer getPayment() {
		return payment;
	}

	public void setPayment(Integer payment) {
		this.payment = payment;
	}

	public String getOldSaleBillId() {
		return oldSaleBillId;
	}

	public void setOldSaleBillId(String oldSaleBillId) {
		this.oldSaleBillId = oldSaleBillId;
	}

	public Set<SaleBillEntry> getEntries() {
        return entries;
    }

    public void setEntries(Set<SaleBillEntry> entries) {
        this.entries = entries;
    }

    public User getMember() {
        return member;
    }

    public void setMember(User member) {
        this.member = member;
    }

    public BigDecimal getReceivable() {
        return receivable;
    }

    public void setReceivable(BigDecimal receivable) {
        if (receivable == null) {
            receivable = BigDecimal.ZERO;
        }

        this.receivable = receivable;
    }

    public BigDecimal getReceived() {
        return received;
    }

    public void setReceived(BigDecimal received) {
        if (received == null) {
            received = BigDecimal.ZERO;
        }

        this.received = received;
    }

    public String getMemberId() {
        if (memberId == null && member != null) {
            memberId = member.getId();
        }

        return memberId;
    }

    public void setMemberId(String memberId) {
        this.memberId = memberId;
    }

    public String getMemberName() {
        if (memberName == null && member != null) {
            memberName = member.getName();
        }

        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public BigDecimal getMemberBalance() {
        return memberBalance;
    }

    public void setMemberBalance(BigDecimal memberBalance) {
        this.memberBalance = memberBalance;
    }
}
